package com.edu;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

//动作和行为
public class ActionContext {

    //线程的安全设置
    private static final ThreadLocal<ActionContext> contextLocal = new ThreadLocal<>();

    private HttpServletResponse response;

    private HttpServletRequest request;

    private ActionContext(){}

    public static ActionContext getContext(){
        //每一个线程存放到每一个位置，不会出现超载存放资源。
        if (contextLocal.get()==null){
            ActionContext context = new ActionContext();
            contextLocal.set(context);
        }
        return contextLocal.get();
    }

    public HttpServletResponse getResponse() {
        return getContext().response;
    }

    public void setResponse(HttpServletResponse response) {
        this.response = response;
    }

    public HttpServletRequest getRequest() {
        return getContext().request;
    }

    public void setRequest(HttpServletRequest request) {
        this.request = request;
    }
}
